package com.lagou.util;

import javax.servlet.*;
import java.io.IOException;

public class RequestFilter implements Filter {
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain)
            throws IOException, ServletException {
        try {
            // 设置请求信息到当前线程
            WebRequestHodler.setting(servletRequest);
            System.out.println("RequestFilter-->" + servletRequest.getRemoteAddr());
            filterChain.doFilter(servletRequest, servletResponse);
        } finally {
            WebRequestHodler.remove();
        }
    }

    @Override
    public void destroy() {
    }
}
